<template>
  <div class="lix-edit">
    <input type="text" placeholder="请输入修改的姓名" placeholder-class="lix-edit__placeholder" cursor=10 @input="bindInput" :value="inputValue"/>
    <button @click="submit">保存</button>
  </div>
</template>

<script>
import { USER_SET_INFO } from '../../store/mutation-types';
import { mapGetters, mapActions } from 'vuex';
import Tip from '../../utils/tips';
export default {
  computed: {
    ...mapGetters('user', {
      name: 'realname'
    })
  },
  data() {
    return {
      inputValue: ''
    };
  },
  onLoad() {
    this.inputValue = this.name;
  },
  methods: {
    ...mapActions('user', {
      'changeUserInfo': USER_SET_INFO
    }),
    bindInput(e) {
      const value = e.mp.detail.value;
      this.inputValue = value;
    },
    submit(e) {
      this.changeUserInfo({
        params: {'realname': this.inputValue},
        callback: function() {
          Tip.success('修改成功')
            .then(res => {
              wx.navigateBack();
            });
        }
      });
    }
  }
};
</script>

<style lang="scss">
@import "../../theme-chalk/edit";
</style>
